home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-06-06 | 3.5 KB | 144 lines | [TEXT/CWIE] |
- {•This sourcecode is an example for creating a FKey coderesource with•}
- {•Metrowerks Pascal. It is copyrighted by Peter Hoerster and released•}
- {•for free use in any Shareware or Freeware product as a way to thank all•}
- {•programmers who share code snippets. You may put this sources on any•}
- {•CD ROM or any Archive Server but you may not sell it. •}
-
- {• For comments please write to <hoerster@muenster.de>•}
-
- unit SaveFile;
-
- interface
-
- uses
- Types, OSUtils, GestaltEqu, Script, notification, Resources, Events,
- PascalA4, QuickDraw, ToolUtils, Memory, LowMem, Scrap,StandardFile;
-
-
-
- {$MAIN}
-
- procedure main;
-
- implementation
-
-
- procedure main;
- var
- oldA4: LongInt;
- myerr: oserr;
- myclipsize: longint;
- myclipHandle: handle;
- longzero, longcount: longint;
- count: longint;
- gsaveref: integer;
-
- function PutFile (saveas: string; var default: string; var gsaveReply: sfreply): OSErr;
- var
- where: Point;
-
- begin
- SetPt(where, 104, 100);
- SFPutFile(where, saveas, default, nil, gsaveReply);
- if not gsaveReply.good then
- PutFile := 1
- else
- begin
- default := gsaveReply.fname;
- PutFile := NoErr
- end;
- end;
-
-
- function PrepareNewFile (thetype: OSType): boolean;
- var
- myNewFile: string;
- gsaveReply: sfreply;
- begin
- PrepareNewFile := false;
- myNewFile := thetype;
- if PutFile(thetype, myNewFile, gsaveReply) = noerr then
- if Create(gsaveReply.fname, gsaveReply.vRefNum, 'ttxt', thetype) = noerr then
- if FSOpen(gsaveReply.fname, gsaveReply.vRefNum, gsaveref) = noerr then
- if SetEOF(gsaveRef, 0) = noerr then
- PrepareNewFile := true;
- end;
-
-
-
-
- procedure dosave ;
- const
- HeaderSize = 512; { PICT file header - we ignore this }
- var
- i:longint;
- begin
- gsaveref := 0;
- myclipsize := GetScrap(nil, 'TEXT', count);
- if myclipsize > 0 then
- begin
- if PrepareNewFile('TEXT') then
- begin
- mycliphandle := Tempnewhandle(myclipsize,myerr);
- if myerr=noerr then
- begin
- myclipsize := GetScraP(myclipHandle, 'TEXT', count);
- if myclipsize > 0 then
- begin
- Temphlock(mycliphandle,myerr);
- if setfpos(gsaveref, fsfromLEOF, 0) = noerr then
- if FSWrite(gsaveref, gethandlesize(mycliphandle), mycliphandle^) = noerr then
- ;
- Temphunlock(myCliphandle,myerr);
- end;
- end;
- end;
- end
- else
- begin
- myclipsize := GetScrap(nil, 'PICT', count);
- if myclipsize > 0 then
- begin
- if PrepareNewFile('PICT') then
- begin
- mycliphandle := Tempnewhandle(myclipsize,myerr);
- if myerr=noerr then
- begin
- myclipsize := GetScrap(mycliphandle, 'PICT', count);
- if myclipsize > 0 then
- begin
- Temphlock(mycliphandle,myerr);begin
- longZero := 0;
- longCount := 4;
- for i := 1 to (512 + SizeOf(Picture)) div 4 do
- begin
- if FSWrite(gsaveref, longCount, @longZero) = noerr then
- if SetFPos(gsaveref, fsFromStart, 512) = noErr then
- if FSWrite(gsaveref, myclipsize, mycliphandle^) = noerr then
- ;
- end;
- Temphunlock(myCliphandle,myerr);
- end;
- end;
- end;
- end;
- end;
- end;
- if gsaveref <> 0 then
- begin
- myerr := FSclose(gsaveref);
- gsaveref := 0;
- end;
- end;
-
-
-
-
- begin
- oldA4 := SetCurrentA4;
- dosave;
- if (mycliphandle <>nil)&(mycliphandle^<>nil) then
- TempDisposeHandle(myCliphandle,myerr);
- oldA4 := SetA4(oldA4);
- end;
- end.